<?php

namespace app\models\Child;

use Yii;

/**
 * This is the model class for table "t_order_service_detail".
 *
 * @property integer $rel_id
 * @property string $booking_no
 * @property integer $order_id
 * @property string $order_no
 * @property integer $service_type
 * @property integer $service_id
 * @property string $cashier_id
 * @property string $user_id
 * @property string $doctor_id
 * @property string $subclinic_id
 * @property integer $patient_id
 * @property integer $order_num
 * @property string $service_name
 * @property string $service_img
 * @property string $service_cost
 * @property string $service_income
 * @property string $service_sum_cost
 * @property string $service_sum_income
 * @property string $create_time
 */
class TOrderServiceDetail extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_order_service_detail';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_id', 'service_type', 'service_id', 'patient_id', 'order_num'], 'integer'],
            [['service_cost', 'service_income', 'service_sum_cost', 'service_sum_income'], 'number'],
            [['create_time'], 'safe'],
            [['booking_no', 'order_no', 'cashier_id', 'user_id', 'doctor_id', 'subclinic_id'], 'string', 'max' => 32],
            [['service_name'], 'string', 'max' => 50],
            [['service_img'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'rel_id' => 'Rel ID',
            'booking_no' => 'Booking No',
            'order_id' => 'Order ID',
            'order_no' => 'Order No',
            'service_type' => 'Service Type',
            'service_id' => 'Service ID',
            'cashier_id' => 'Cashier ID',
            'user_id' => 'User ID',
            'doctor_id' => 'Doctor ID',
            'subclinic_id' => 'Subclinic ID',
            'patient_id' => 'Patient ID',
            'order_num' => 'Order Num',
            'service_name' => 'Service Name',
            'service_img' => 'Service Img',
            'service_cost' => 'Service Cost',
            'service_income' => 'Service Income',
            'service_sum_cost' => 'Service Sum Cost',
            'service_sum_income' => 'Service Sum Income',
            'create_time' => 'Create Time',
        ];
    }
    
    /*
     * 根据订单id获取相关信息
     */
    public function TOrderService($order_id)
    {
        $list = $this->find()
                ->select('t_order_service_detail.order_no,rel_id,t_order_service_detail.service_img,init_service_info.service_name,t_order_service_detail.doctor_id,sys_user_info.user_name as doctor_name,sys_user_info.user_id,t_user_info.user_name,init_service_info.service_cost,order_num,service_sum_cost')
                ->join('left join','init_service_info','init_service_info.service_id = t_order_service_detail.service_id')
                ->join('left join','sys_user_info','sys_user_info.user_id = t_order_service_detail.doctor_id')
                ->join('left join','t_user_info','t_user_info.user_id = t_order_service_detail.user_id')
                ->where(['order_id' => $order_id])
                ->asArray()
                ->all();
        
        return $list;
    }
}
